<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>API-race</title>
</head>
<body>
  <script>
    const p1 = Promise.resolve('p1 resolve');
    const p2 = Promise.resolve('p2 resolve');
    const p3 = new Promise((resolve, reject) => {
      setTimeout(() => {
        resolve('p3 resolve'); // p3 延时 1s 返回
      }, 1000);
    });
    const p4 = Promise.reject('p4 reject');
    // p4.catch(reason => {{
    //   console.log('p4 失败', reason); // 在这里捕获第一次失败
    // }});

    const p = Promise.race([p3, p4, p1, p2]); // 哪个 Promise 先执行完毕就返回哪个 Promise 的状态及返回值
    p.catch(reason => {{
      console.log('p 失败', reason); 
    }});
    console.log(p); // 此情况返回 p4 的状态及结果
  </script>
</body>
</html>